<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>请假信息</title>
<meta name="decorator" content="default" />
<script src="${ctxStatic}/front/js/myValidate.js"></script>
<script type="text/javascript">
		$(document).ready(function() {
			$("#inputForm").validate({
							rules : {
								startDate : {
									required : true
								},
								reason : {
									required : true
								},
								parentId: {
									required : true
								},
								studentId: {
									required : true
								},
								days : {
									required : true,
									digits : true,
									min : 0
								}
							},
							messages : {
								startDate : {
									required : "请填写"
								},
								reason : {
									required : "请填写"
								},
								parentId: {
									required : "请选择"
								},
								studentId: {
									required : "请选择"
								},
								days : {
									required : "请选择",
									digits : "请填写正整数",
									min : "必须大于0"
								}
							},
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
			$("#parentId").change(function(){
		        var parentId=$("#parentId").val();
		     $.ajax({
		         type: "POST",
		         url: "${ctx}/ajax/get/student.do",
		         data: {"parentId":parentId},
		         dataType: 'json',
		         success: function(data) {
		               $("#studentId").empty();
		               $("#studentId").append("<option selected=\"selected\" value=\"\">请选择</option>" );
		               $.each(data, function(index,item){
		             		$("#studentId").append('<option value='+item.id+'>'+item.name+'</option>');
		              }); 
		               $("#s2id_studentId").find("span[class='select2-chosen']").html("请选择");
		             }
		  		});
		     });
		});
 </script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li><a href="${ctx}/dd/ddLeave/">请假列表</a></li>
		<li class="active"><a
			href="${ctx}/dd/ddLeave/form?id=${ddLeave.id}">请假<shiro:hasPermission
					name="dd:ddLeave:edit">${not empty ddLeave.id?'修改':'添加'}</shiro:hasPermission>
				<shiro:lacksPermission name="dd:ddLeave:edit">查看</shiro:lacksPermission></a></li>
	</ul>
	<br />
	<form:form id="inputForm" modelAttribute="ddLeave"
		action="${ctx}/dd/ddLeave/save" method="post" class="form-horizontal">
		<form:hidden path="id" />
		<sys:message content="${message}" />
		<div class="control-group">
			<label class="control-label"><b
				style="color: red; font-size: large">*</b>家长：</label>
			<div class="controls">
				<form:select path="parentId" required="required"
					class="input-mini form-control required ">
					<form:option value="">请选择</form:option>
					<form:options items="${fns:getParentNameList()}" itemLabel="name"
						itemValue="id" htmlEscape="false" />
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><b
				style="color: red; font-size: large">*</b>学生：</label>
			<div class="controls">
				<form:select path="studentId" required="required"
					class="input-mini form-control required ">
					<%-- <form:option value="">请选择</form:option>
					<form:options items="${fns:getStudentNameList()}" itemLabel="name"
						itemValue="id" htmlEscape="false" /> --%>
						<form:option value="" selected="selected">请选择</form:option> 
				</form:select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><b
				style="color: red; font-size: large">*</b>请假天数：</label>
			<div class="controls">
				<form:input path="days" htmlEscape="false" min="0" maxlength="11" required="required"
					type="number" class="input-xlarge " />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><b
				style="color: red; font-size: large">*</b>请假开始日期：</label>
			<div class="controls">
				<input name="startDate" type="text" readonly="readonly"
					maxlength="20" class="input-medium Wdate " required="required"
					value="<fmt:formatDate value="${ddLeave.startDate}" pattern="yyyy-MM-dd"/>"
					onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});" />
			</div>
		</div>
		<div class="control-group">
			<label class="control-label"><b
				style="color: red; font-size: large">*</b>请假理由：</label>
			<div class="controls">
				<form:input path="reason" htmlEscape="false" maxlength="2000" required="required"
					class="input-xlarge " />
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="dd:ddLeave:edit">
				<input id="btnSubmit" class="btn btn-primary" type="submit"
					value="保 存" />&nbsp;</shiro:hasPermission>
			<input id="btnCancel" class="btn" type="button" value="返 回"
				onclick="history.go(-1)" />
		</div>
	</form:form>
</body>
</html>